package com.ruoyi.medicine.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.medicine.domain.MedicineCategory;
import com.ruoyi.medicine.service.IMedicineCategoryService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 药品分类Controller
 * 
 * @author ruoyi
 * @date 2024-04-07
 */
@RestController
@RequestMapping("/medicine/category")
public class MedicineCategoryController extends BaseController
{
    @Autowired
    private IMedicineCategoryService medicineCategoryService;

    /**
     * 查询药品分类列表
     */
    @PreAuthorize("@ss.hasPermi('medicine:category:list')")
    @GetMapping("/list")
    public TableDataInfo list(MedicineCategory medicineCategory)
    {
        startPage();
        List<MedicineCategory> list = medicineCategoryService.selectMedicineCategoryList(medicineCategory);
        return getDataTable(list);
    }

    /**
     * 导出药品分类列表
     */
    @PreAuthorize("@ss.hasPermi('medicine:category:export')")
    @Log(title = "药品分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MedicineCategory medicineCategory)
    {
        List<MedicineCategory> list = medicineCategoryService.selectMedicineCategoryList(medicineCategory);
        ExcelUtil<MedicineCategory> util = new ExcelUtil<MedicineCategory>(MedicineCategory.class);
        util.exportExcel(response, list, "药品分类数据");
    }

    /**
     * 获取药品分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('medicine:category:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(medicineCategoryService.selectMedicineCategoryById(id));
    }

    /**
     * 新增药品分类
     */
    @PreAuthorize("@ss.hasPermi('medicine:category:add')")
    @Log(title = "药品分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MedicineCategory medicineCategory)
    {
        return toAjax(medicineCategoryService.insertMedicineCategory(medicineCategory));
    }

    /**
     * 修改药品分类
     */
    @PreAuthorize("@ss.hasPermi('medicine:category:edit')")
    @Log(title = "药品分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MedicineCategory medicineCategory)
    {
        return toAjax(medicineCategoryService.updateMedicineCategory(medicineCategory));
    }

    /**
     * 删除药品分类
     */
    @PreAuthorize("@ss.hasPermi('medicine:category:remove')")
    @Log(title = "药品分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(medicineCategoryService.deleteMedicineCategoryByIds(ids));
    }
}
